home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWSlcing.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  18.6 KB  |  604 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSlcing.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWSLCING_H
  13. #include "FWSlcing.h"
  14. #endif
  15.  
  16. #ifndef FWPROXY_H
  17. #include "FWProxy.h"
  18. #endif
  19.  
  20. #ifndef FWPRESEN_H
  21. #include "FWPresen.h"
  22. #endif
  23.  
  24. #ifndef FWFRMING_H
  25. #include "FWFrming.h"
  26. #endif
  27.  
  28. #ifndef FWPXYFRM_H
  29. #include "FWPxyFrm.h"
  30. #endif
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWCLNINF_H
  37. #include "FWClnInf.h"
  38. #endif
  39.  
  40. // ----- OS Includes -----
  41.  
  42. #ifndef FWBARRAY_H
  43. #include "FWBArray.h"
  44. #endif
  45.  
  46. #ifndef FWODGEOM_H
  47. #include "FWODGeom.h"
  48. #endif
  49.  
  50. // ----- OD Utils -----
  51.  
  52. #ifndef _EDITRSET_
  53. #include "EditrSet.h"
  54. #endif
  55.  
  56. #ifndef _BNDNSUTL_
  57. #include "BndNSUtl.h"
  58. #endif
  59.  
  60. // ----- Foundation -----
  61.  
  62. #ifndef FWSTRING_H
  63. #include "FWString.h"
  64. #endif
  65.  
  66. // ----- OpenDoc Includes -----
  67.  
  68. #ifndef SOM_Module_OpenDoc_StdProps_defined
  69. #include <StdProps.xh>
  70. #endif
  71.  
  72. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  73. #include <StdTypes.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODSession_xh
  77. #include <ODSessn.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODWindowState_xh
  81. #include "WinStat.xh"
  82. #endif
  83.  
  84. // ----- Macintosh Includes -----
  85.  
  86. #if defined(FW_BUILD_MAC) && !defined(__STANDARDFILE__)
  87. #include <StandardFile.h>
  88. #endif
  89.  
  90. #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
  91. #include <Resources.h>
  92. #endif
  93.  
  94. //========================================================================================
  95. // RunTime Info
  96. //========================================================================================
  97.  
  98. #if FW_LIB_EXPORT_PRAGMAS
  99. #pragma lib_export on
  100. #endif
  101.  
  102. #ifdef FW_BUILD_MAC
  103. #pragma segment fw_embedding2
  104. #endif
  105.  
  106. FW_DEFINE_CLASS_M1(FW_CEmbeddingSelection, FW_CSelection)
  107.  
  108. //========================================================================================
  109. //    class FW_CEmbeddingSelection
  110. //========================================================================================
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    FW_CEmbeddingSelection::FW_CEmbeddingSelection
  114. //----------------------------------------------------------------------------------------
  115.  
  116. FW_CEmbeddingSelection::FW_CEmbeddingSelection(Environment* ev, 
  117.                                                 FW_Boolean allowPublish, 
  118.                                                 FW_Boolean allowSubscribe) :
  119.             FW_CSelection(ev, allowPublish, allowSubscribe)
  120. {
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_CEmbeddingSelection::~FW_CEmbeddingSelection
  125. //----------------------------------------------------------------------------------------
  126.  
  127. FW_CEmbeddingSelection::~FW_CEmbeddingSelection()
  128. {
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CEmbeddingSelection::IsSelectionOnlyOneProxy
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_MProxy* FW_CEmbeddingSelection::IsSelectionOnlyOneProxy(Environment* ev) const
  136. {
  137.     return NULL;
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_CEmbeddingSelection::PrivPostInternalizeSelection
  142. //----------------------------------------------------------------------------------------
  143.  
  144. void FW_CEmbeddingSelection::PrivPostInternalizeSelection(Environment* ev, 
  145.                                                         FW_CCloneInfo* cloneInfo, 
  146.                                                         FW_EInternalizeResult result)
  147. {
  148.     switch (result)
  149.     {
  150.         case FW_kInternalizeFailed:
  151.             FW_DEBUG_MESSAGE("PrivPostInternalizeSelection should not have been called");
  152.             break;
  153.             
  154.         case FW_kInternalizeContent:
  155.             PrivPostInternalizeContent(ev, cloneInfo);
  156.             break;
  157.             
  158.         case FW_kInternalizePart:
  159.             PrivPostInternalizePart(ev, cloneInfo);
  160.             break;
  161.             
  162.         case FW_kInternalizeFrame:
  163.             PrivPostInternalizeFrame(ev, cloneInfo);
  164.             break;
  165.     }
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    FW_CEmbeddingSelection::PrivPostInternalizeContent
  170. //----------------------------------------------------------------------------------------
  171.  
  172. void FW_CEmbeddingSelection::PrivPostInternalizeContent(Environment* ev, FW_CCloneInfo* cloneInfo)
  173. {
  174.     if (cloneInfo->fClonedProxyList == NULL)    // No embedded frames have been read
  175.         return;
  176.         
  177.     FW_COrderedCollectionIterator ite(cloneInfo->fClonedProxyList);
  178.     for (FW_MProxy* proxy = (FW_MProxy*)ite.First(); ite.IsNotComplete(); proxy = (FW_MProxy*)ite.Next())
  179.     {
  180.         proxy->PrivPostClone(ev, cloneInfo->GetScopeFrame(ev));
  181.     }
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    FW_CEmbeddingSelection::PrivPostInternalizePart
  186. //----------------------------------------------------------------------------------------
  187.  
  188. void FW_CEmbeddingSelection::PrivPostInternalizePart(Environment* ev, FW_CCloneInfo* cloneInfo)
  189. {
  190.     FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  191.     FW_ASSERT(cloneInfo->fClonedFrameID == kODNULLID);
  192.     
  193.     ODDraft* myDraft = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
  194.     FW_CAcquiredODPart aqEmbeddedPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
  195.     
  196.     FW_CEmbeddingFrame* embeddingScopeFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
  197.     FW_ASSERT(embeddingScopeFrame);
  198.  
  199.     embeddingScopeFrame->EmbedSingleFrame(ev, 
  200.                                         aqEmbeddedPart, 
  201.                                         NULL, 
  202.                                         cloneInfo->fFrameShape);
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. //    FW_CEmbeddingSelection::PrivPostInternalizeFrame
  207. //----------------------------------------------------------------------------------------
  208.  
  209. void FW_CEmbeddingSelection::PrivPostInternalizeFrame(Environment* ev, FW_CCloneInfo* cloneInfo)
  210. {
  211.     FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  212.     FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
  213.  
  214.     FW_CEmbeddingFrame* scopeEmbeddingFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
  215.     FW_ASSERT(scopeEmbeddingFrame);
  216.  
  217.     // ----- Get the part -----
  218.     ODDraft* myDraft = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
  219.     FW_CAcquiredODPart aqNewPart = myDraft->AcquirePart(ev, cloneInfo->fClonedPartID);
  220.     FW_ASSERT(aqNewPart != NULL);
  221.         
  222.     FW_TRY
  223.     {
  224.         FW_CAcquiredODFrame aqNewFrame = myDraft->AcquireFrame(ev, cloneInfo->fClonedFrameID);
  225.         FW_ASSERT(aqNewFrame != NULL);
  226.  
  227.         aqNewFrame->SetContainingFrame(ev, scopeEmbeddingFrame->GetODFrame(ev));
  228.         
  229.         FW_CAcquiredODShape aqFrameShape = aqNewFrame->AcquireFrameShape(ev, NULL);
  230.             
  231.         scopeEmbeddingFrame->EmbedSingleFrame(ev, 
  232.                                             aqNewPart, 
  233.                                             aqNewFrame, 
  234.                                             aqFrameShape);
  235.     }
  236.     FW_CATCH_BEGIN
  237.     FW_CATCH_EVERYTHING()
  238.     {
  239.         FW_THROW_SAME();
  240.     }
  241.     FW_CATCH_END
  242. }
  243.  
  244. //----------------------------------------------------------------------------------------
  245. //    FW_CEmbeddingSelection::PrivHandleExternalizeSelection
  246. //----------------------------------------------------------------------------------------
  247. //    Here we have two cases: 
  248. //        1) The selection consist of only one embedded part. In this case
  249. //            we just want to clone it into the clipboard
  250. //        2) The selection is two or more embedded parts or one or more
  251. //            embedded parts plus content. In this case we externalize the selection
  252.  
  253. void FW_CEmbeddingSelection::PrivHandleExternalizeSelection(Environment* ev, 
  254.                                                         FW_EStorageKinds storageKind, 
  255.                                                         ODStorageUnit* destinationSU,
  256.                                                         FW_CCloneInfo* cloneInfo)
  257. {
  258.     FW_ASSERT(cloneInfo->GetScopeFrame(ev));
  259.     
  260.     FW_MProxy *selectedProxy = IsSelectionOnlyOneProxy(ev);
  261.     if (selectedProxy)        // if the selection is only one embedded frame clone it into the clipboard 
  262.     {
  263.         FW_CEmbeddingFrame* embeddingFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, cloneInfo->GetScopeFrame(ev));
  264.         FW_ASSERT(embeddingFrame);
  265.  
  266.         ODFrame* odEmbeddedFrame = selectedProxy->GetEmbeddedFrame(ev, embeddingFrame);    
  267.         FW_ASSERT(odEmbeddedFrame);
  268.         
  269.         DoExternalizeSingleEmbeddedFrame(ev, odEmbeddedFrame, destinationSU, cloneInfo);        
  270.     
  271.     }
  272.     else
  273.     {
  274.         // ----- First write out our embedded frames -----
  275.         FW_CSelection::PrivHandleExternalizeSelection(ev, storageKind, destinationSU, cloneInfo);
  276.     }
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. //    FW_CEmbeddingSelection::DoExternalizeSingleEmbeddedFrame
  281. //----------------------------------------------------------------------------------------
  282.  
  283. void FW_CEmbeddingSelection::DoExternalizeSingleEmbeddedFrame(Environment* ev, 
  284.                                         ODFrame* odEmbeddedFrame, 
  285.                                         ODStorageUnit* destinationSU, 
  286.                                         FW_CCloneInfo* cloneInfo)
  287. {            
  288.     destinationSU->AddProperty(ev, kODPropContentFrame);
  289.     destinationSU->AddValue(ev, kODWeakStorageUnitRef);
  290.         
  291.     //    Clone the embedded part into the root storage unit.
  292.     FW_CAcquiredODPart aqPart = odEmbeddedFrame->AcquirePart(ev);
  293.     ODID toRootID = cloneInfo->Clone(ev, aqPart->GetID(ev), destinationSU->GetID(ev), odEmbeddedFrame->GetID(ev));
  294.         
  295.     // Clone the embedded Frame to any storage unit. Must be done
  296.     // after cloning the part because strongly reference the part
  297.     ODID toFrameID = cloneInfo->Clone(ev, odEmbeddedFrame->GetID(ev), 0, odEmbeddedFrame->GetID(ev));
  298.         
  299.     //    Weakly reference the frame
  300.     destinationSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
  301.         
  302.     ODStorageUnitRef aSURef;
  303.     destinationSU->GetWeakStorageUnitRef(ev, toFrameID, aSURef);
  304.     
  305.     FW_CByteArray byteArray(&aSURef, sizeof(ODStorageUnitRef));
  306.     destinationSU->SetValue(ev, byteArray);
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. //    FW_CEmbeddingSelection::PrivHandleInternalizeSelection
  311. //----------------------------------------------------------------------------------------
  312.  
  313. FW_EInternalizeResult FW_CEmbeddingSelection::PrivHandleInternalizeSelection(Environment* ev, 
  314.                                                                 ODStorageUnit* sourceSU,
  315.                                                                 FW_CCloneInfo* cloneInfo)
  316. {
  317.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  318.     
  319.     // ----- Test first if the was copy/cut of a single embedded frame
  320.     if (sourceSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  321.     {
  322.         result = DoInternalizeSingleEmbeddedFrame(ev, sourceSU, cloneInfo);
  323.     }
  324.     else
  325.     {
  326.         // ----- Try to incorporate -----
  327.         result = FW_CSelection::PrivHandleInternalizeSelection(ev, sourceSU, cloneInfo);
  328.  
  329.         // ----- Then try embedding -----
  330.         if (result == FW_kInternalizeFailed)
  331.         {
  332.             // ----- Clone the part -----            
  333.             cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
  334.             FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  335.             result = FW_kInternalizePart;
  336.             
  337.             // ----- Look for the frame shape -----    
  338.             cloneInfo->fFrameShape = PrivReadFrameShape(ev, sourceSU);
  339.         }
  340.     }
  341.     
  342.     return result;
  343. }
  344.  
  345. //----------------------------------------------------------------------------------------
  346. //    FW_CEmbeddingSelection::PrivReadFrameShape
  347. //----------------------------------------------------------------------------------------
  348.  
  349. ODShape* FW_CEmbeddingSelection::PrivReadFrameShape(Environment* ev, ODStorageUnit* sourceSU)
  350. {
  351.     // ----- Look for a frame shape property -----
  352.     ODShape* frameShape = NULL;
  353.     
  354.     if (sourceSU->Exists(ev, kODPropFrameShape, (ODValueType)NULL, 0))
  355.     {
  356.         // ----- Note: we focus on the property, ReadShape will focus on the value
  357.         sourceSU->Focus(ev, kODPropFrameShape, 
  358.                             kODPosUndefined, 
  359.                                (ODValueType)NULL, 
  360.                             (ODValueIndex)1, 
  361.                             kODPosUndefined);
  362.         
  363.         frameShape = ::FW_NewODShape(ev);
  364.         frameShape = frameShape->ReadShape(ev, sourceSU);
  365.     }
  366.     
  367.     return frameShape;
  368. }
  369.  
  370. //----------------------------------------------------------------------------------------
  371. //    FW_CEmbeddingSelection::DoInternalizeSingleEmbeddedFrame
  372. //----------------------------------------------------------------------------------------
  373.  
  374. FW_EInternalizeResult FW_CEmbeddingSelection::DoInternalizeSingleEmbeddedFrame(Environment* ev, 
  375.                                                                                 ODStorageUnit* sourceSU,
  376.                                                                                 FW_CCloneInfo* cloneInfo)
  377. {
  378.     FW_EInternalizeResult result = FW_kInternalizeFailed;
  379.     
  380.     ODDraft* myDraft = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev)->GetDraft(ev);
  381.     
  382.     cloneInfo->fClonedPartID = cloneInfo->Clone(ev, sourceSU->GetID(ev), 0, 0);
  383.     FW_ASSERT(cloneInfo->fClonedPartID != kODNULLID);
  384.     
  385.     result = FW_kInternalizePart;
  386.  
  387.     // ----- Try Cloning the frame -----
  388.     ODStorageUnitRef aSURef;
  389.     sourceSU->Focus(ev, kODPropContentFrame, kODPosUndefined, kODWeakStorageUnitRef, 0, kODPosUndefined);
  390.     
  391.     FW_CByteArray byteArray; 
  392.     sourceSU->GetValue(ev, sizeof(aSURef), byteArray);
  393.     byteArray.CopyBuffer( &aSURef, sizeof(aSURef));
  394.  
  395.     if (sourceSU->IsValidStorageUnitRef(ev, aSURef))
  396.     {
  397.         ODID sourceFrameID = sourceSU->GetIDFromStorageUnitRef(ev, aSURef);
  398.         cloneInfo->fClonedFrameID = cloneInfo->Clone(ev, sourceFrameID, 0, 0);
  399.         FW_ASSERT(cloneInfo->fClonedFrameID != kODNULLID);
  400.         
  401.         result = FW_kInternalizeFrame;
  402.     }
  403.     
  404.     return result;
  405. }
  406.  
  407. /*
  408. //----------------------------------------------------------------------------------------
  409. // CreateFileContainer
  410. //----------------------------------------------------------------------------------------
  411.  
  412. ODContainer* CreateFileContainer(Environment* ev, ODSession* session, FSSpec* fsSpec)
  413. {
  414.     ODByteArray* ba = CreateByteArray(fsSpec, sizeof(FSSpec));
  415.     ODContainer* newContainer = session->GetStorageSystem(ev)->CreateContainer(ev, kODDefaultFileContainer, ba);
  416.     DisposeByteArray(ba);
  417.     
  418.     return newContainer;
  419. }
  420.  
  421. //----------------------------------------------------------------------------------------
  422. //    FW_CEmbeddingSelection::InsertNewPart
  423. //----------------------------------------------------------------------------------------
  424.  
  425. FW_Boolean FW_CEmbeddingSelection::InsertNewPart(Environment* ev, FW_CFrame* scopeFrame)
  426. {    
  427.     FW_Boolean result = FALSE;
  428.     ODStorageUnit* partSU = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev);
  429.     ODSession* session = partSU->GetSession(ev);
  430.     ODWindowState* windowState = session->GetWindowState(ev);
  431.     ODContainer* insertContainer = NULL;
  432.     ODDocument* insertDocument = NULL;
  433.     
  434.     ODType    partkind = NULL;
  435.  
  436.     // ----- StdGetFile please select an editor for the root part
  437.     StandardFileReply sfReply;
  438.     SFTypeList sfTypes;
  439.     
  440.     windowState->DeactivateFrontWindows(ev);
  441.     StandardGetFile((FileFilterUPP)NULL,-1,sfTypes,&sfReply);
  442.     windowState->ActivateFrontWindows(ev);
  443.     
  444.     // If the user selected a file and clicked 'OK'
  445.     if (sfReply.sfGood) 
  446.     {
  447.         insertContainer = CreateFileContainer(ev, session, &(sfReply.sfFile));
  448.     
  449.         // If the user chose an OpenDoc ODContainer
  450.         if (insertContainer != NULL)
  451.         {
  452.             insertDocument = insertContainer->GetDocument(ev, kODDefaultDocument);
  453.             ODDraft* nextDraft = NULL;
  454.             ODDraft* insertDraft = insertDocument->GetBaseDraft(ev, kDPReadOnly);
  455.         
  456.             // New method for iterating over drafts in document without relying on failure
  457.             if (insertDocument->Exists(ev, 0, insertDraft, kODPosLastAbove))
  458.                 do
  459.                 {
  460.                     insertDraft = insertDocument->GetDraft(ev, kDPReadOnly, NULL, insertDraft, kODPosLastAbove, TRUE);
  461.                 } while (insertDocument->Exists(ev, 0, insertDraft, kODPosLastAbove));
  462.                     
  463.             ODStorageUnit* draftSU = insertDraft->GetDraftProperties(ev);
  464.             ODStorageUnitRef suRef;
  465.             draftSU->Focus(ev, kODPropRootPartSU, kODPosUndefined, kODStrongStorageUnitRef, 0, kODPosUndefined);
  466.             draftSU->GetValue(ev, sizeof(ODStorageUnitRef), &suRef);
  467.             ODStorageUnit* insertSU = insertDraft->GetStorageUnit(ev, draftSU->GetIDFromStorageUnitRef(ev, suRef));
  468.         
  469.             // ----- Clone the root part from the insertDraft to this Draft. As per Insert recipe.
  470.             ODID scopeFrameID = scopeFrame->GetODFrame(ev)->GetStorageUnit(ev)->GetID(ev);
  471.             ODDraft* destinationDraft = partSU->GetDraft(ev);
  472.             ODDraftKey key = insertDraft->BeginClone(ev, destinationDraft, kODClonePaste);
  473.             
  474.             FW_TRY
  475.             {
  476.                 insertSU->CloneInto(ev, key, partSU, scopeFrameID);
  477.             }
  478.             FW_CATCH_BEGIN
  479.             FW_CATCH_EVERYTHING()
  480.             {
  481.                 // If an exception was raised while cloning, abort the insert
  482.                 insertDraft->AbortClone(ev, key);
  483.                 FW_THROW_SAME();
  484.             }
  485.             FW_CATCH_END
  486.  
  487.             insertDraft->EndClone(ev, key);
  488.             
  489.             ODPart* newPart = partSU->GetDraft(ev)->GetPart(ev, insertSU->GetID(ev));
  490.             
  491.             // ----- Get the frame shape if any
  492.             ODShape* frameShape = NULL;
  493.             FW_VOLATILE(frameShape);
  494.             
  495.             FW_TRY
  496.             {
  497.                 if (insertSU->Exists(ev, kODPropFrameShape, NULL, 0))
  498.                 {
  499.                     frameShape = ::FW_NewODShape(ev);
  500.                     insertSU->Focus(ev, kODPropFrameShape, kODPosUndefined, NULL, 0, kODPosUndefined);
  501.                     frameShape->ReadShape(ev, insertSU);
  502.                 }
  503.                 
  504.                 result = EmbedPart(ev, newPart, frameShape);
  505.                 
  506.                 FW_ReleaseODObject(ev, frameShape);
  507.                 frameShape = NULL
  508.             }
  509.             FW_CATCH_BEGIN
  510.             FW_CATCH_EVERYTHING()
  511.             {
  512.                 FW_ReleaseODObject(frameShape);
  513.                 FW_THROW_SAME();
  514.             }
  515.             FW_CATCH_END
  516.             
  517.             // ----- Release -----
  518.             FW_ReleaseODObject(ev, newPart);            
  519.             FW_ReleaseODObject(ev, insertSU);
  520.             FW_ReleaseODObject(ev, draftSU);
  521.             FW_ReleaseODObject(ev, insertDraft);
  522.             FW_ReleaseODObject(ev, insertDocument);
  523.             FW_ReleaseODObject(ev, insertContainer);
  524.                         
  525.             result = TRUE;            
  526.         }
  527.         
  528.     }
  529.         
  530.     return result;
  531. }
  532. */
  533.  
  534. //----------------------------------------------------------------------------------------
  535. //    FW_CEmbeddingSelection::InsertNewPart
  536. //----------------------------------------------------------------------------------------
  537. // This is the wrong way to do Insert but it's fine for now
  538.  
  539. FW_Boolean FW_CEmbeddingSelection::InsertNewPart(Environment* ev, FW_CFrame* scopeFrame)
  540. {
  541.     FW_Boolean result = FALSE;
  542.     
  543. #ifdef FW_BUILD_MAC
  544.     ODPart* odEmbeddedPart;
  545.     ODStorageUnit* su = GetPresentation(ev)->GetPart(ev)->GetStorageUnit(ev);
  546.     
  547.     
  548.     ODType    partkind = NULL;
  549.     FW_CDynamicString partString;
  550.     
  551.     // StdGetFile please select an editor for the root part
  552.     StandardFileReply sfReply;
  553.     SFTypeList sfTypes;
  554.     sfTypes[0] = 'shlb';
  555.     sfTypes[1] = 'shlb';
  556.     sfTypes[2] = 'shlb';
  557.     sfTypes[3] = 'shlb';
  558.     
  559.     ODWindowState* windowState = su->GetSession(ev)->GetWindowState(ev);
  560.  
  561.     windowState->DeactivateFrontWindows(ev);
  562.     ::StandardGetFile((FileFilterUPP)NULL,1,sfTypes,&sfReply);
  563.     windowState->ActivateFrontWindows(ev);
  564.     
  565.     if (sfReply.sfGood) 
  566.     {
  567.         short saveResFile = ::CurResFile();
  568.         short resRefNum = ::FSpOpenResFile(&(sfReply.sfFile),fsRdPerm);
  569.         EditorSet* theEditorSet = ODGetEditorSetFromResFile(resRefNum);
  570.         ::CloseResFile(resRefNum);
  571.         ::UseResFile(saveResFile);
  572.         
  573.         if (theEditorSet)
  574.         {
  575.             EditorSetIterator* itr = theEditorSet->CreateIterator();
  576.             ODEditor editor = itr->First();
  577.             delete itr;
  578.         
  579.             odEmbeddedPart = su->GetDraft(ev)->CreatePart(ev, NULL, editor);
  580.             FW_ASSERT(odEmbeddedPart);
  581.  
  582.             delete theEditorSet;
  583.  
  584.             odEmbeddedPart->Externalize(ev);    // DR3 I don't know why
  585.             ((FW_CEmbeddingFrame*)scopeFrame)->EmbedSingleFrame(ev, 
  586.                                                                 odEmbeddedPart, 
  587.                                                                 NULL, 
  588.                                                                 NULL);
  589.             
  590.             result = TRUE;
  591.             
  592.             odEmbeddedPart->Release(ev); // To balance CreatePart
  593.         }
  594.     }
  595. #endif
  596.  
  597. #ifdef FW_BUILD_WIN
  598.     // Windows code goes here!
  599. #endif
  600.  
  601.     return result;
  602. }
  603.  
  604.